package util;

import java.awt.Color;
import java.awt.Graphics2D;

public class DrawGraph {


	int w, h;
	public String[] nodes = new String[4];
	public int no_nodes = 0;
	public String lastMsgFrom = "NONE";

	public DrawGraph(int w, int h) {
		this.w = w;
		this.h = h;
	}

	public void draw(Graphics2D g) {
		
		int centerX=w/2;
		int centerY=h/2;
		int r =(int)( Math.min(w, h)*0.4);
		int angle_step = 360/no_nodes;

		//debug
		//g.setColor(Color.green);
		//g.drawOval(centerX-r, centerY-r, 2*r, 2*r);

		int circleX, circleY, lastX=0, lastY=0;
		for(int i=0; i<no_nodes ; i++) {
			g.setColor(Color.gray);
			circleX = centerX+(int)(Math.sin(Math.toRadians(angle_step*i))*r);
			circleY =  centerY-(int)(Math.cos(Math.toRadians(angle_step*i))*r);
			g.drawOval(circleX, circleY,5, 5);
			g.setColor(Color.green);
			g.drawString(nodes[i], circleX, circleY);

			if(lastMsgFrom == null)
				System.err.println("lastMsgFrom = null");
			else {
				if(lastMsgFrom.compareTo(nodes[i]) == 0){ //Bugged for D-A connection
					g.setColor(Color.red);
					g.drawLine(lastX, lastY, circleX, circleY);
				}
			}
			lastX = circleX;
			lastY = circleY;
		}
		g.setColor(Color.black);
	}
}
